package com.eshop.tools.express.config;

import com.eshop.enums.ShopCommonEnum;
import com.eshop.tools.express.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import com.eshop.utils.RedisUtils;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class ExpressAutoConfiguration
{
    private static RedisUtils redisUtil;
    
    @Autowired
    public ExpressAutoConfiguration(final RedisUtils redisUtil) {
        ExpressAutoConfiguration.redisUtil = redisUtil;
    }
    
    public static ExpressService expressService() {
        final ExpressService expressService = (ExpressService)ExpressAutoConfiguration.redisUtil.get("yshop_express_service");
        if (expressService != null) {
            return expressService;
        }
        final ExpressProperties properties = new ExpressProperties();
        final String enable = ExpressAutoConfiguration.redisUtil.getY("exp_enable");
        final String appId = ExpressAutoConfiguration.redisUtil.getY("exp_appId");
        final String appKey = ExpressAutoConfiguration.redisUtil.getY("exp_appKey");
        properties.setAppId(appId);
        properties.setAppKey(appKey);
        if (ShopCommonEnum.ENABLE_2.getValue().toString().equals(enable)) {
            properties.setEnable(false);
        }
        else {
            properties.setEnable(true);
        }
        final ExpressService service = new ExpressService();
        service.setProperties(properties);
        ExpressAutoConfiguration.redisUtil.set("yshop_express_service", (Object)service);
        return service;
    }
}
